package com.wp.admin.controller;

import com.wp.admin.pojo.SysUser;
import com.wp.admin.service.SysUserService;
import com.wp.common.vo.PageRequest;
import com.wp.common.vo.PageResult;
import com.wp.model.admin.input.dto.SaveUserInputDTO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Set;

/**
 * @author wp
 * @create 2019-03-04 10:13
 */
@RestController
@RequestMapping(value = "user")
public class SysUserController {

    @Autowired
    private SysUserService sysUserService;

    @ApiOperation(value = "保存用户信息")
    @PostMapping("/save")
    public ResponseEntity<Void> save(@RequestBody SaveUserInputDTO saveUserInputDTO){
        sysUserService.saveUser(saveUserInputDTO);
        return ResponseEntity.status(HttpStatus.OK).build();
    }

    @ApiOperation(value = "根据用户名查询权限")
    @GetMapping("/findPermissionsByUserName")
    public ResponseEntity<Set<String>> findPermissionsByUserName(@RequestParam String userName) {
        return ResponseEntity.ok(sysUserService.findPermissionsByUserName(userName));
    }

    @ApiIgnore
    @GetMapping("/findUserById")
    public SysUser findUserById(@RequestParam Long userId) {
        return sysUserService.findUserById(userId);
    }

    @ApiOperation(value = "分页查询用户")
    @PostMapping("/findPage")
    public ResponseEntity<PageResult<SysUser>> findPage(@RequestBody PageRequest pageRequest) {
        return ResponseEntity.ok(sysUserService.findPage(pageRequest));
    }

}
